package day230518;

import java.util.*;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/5/18 20:15
 * 简单错误记录
 */
public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        // 使用顺序表记录错误记录, 使用map映射记录和出现次数
        List<String> errorLogging = new ArrayList<>();
        Map<String, Integer> loggingMap = new HashMap<>();
        while (scan.hasNext()) {
            String fileName = scan.next(); // 接收文件名或者路径
            String count = scan.next(); // 接收文件代码行数
            // 对文件名进行预处理, 保留最后一个\后的, 且只保留后16位字符
            String[] preString = fileName.split("\\\\"); // 以 \ 进行分隔
            if (preString[preString.length-1].length() > 16) {
                // 保留后十六位
                fileName = preString[preString.length-1].substring(preString[preString.length-1].length()-16);
            } else {
                fileName = preString[preString.length-1];
            }
            // 存储错误记录并更新次数
            String curRecord = fileName + " " + count;
            if (!loggingMap.containsKey(curRecord)) {
                // 如果是第一次出现该记录, 则记录一次, 并将该记录加入顺序表中
                loggingMap.put(curRecord, 1);
                errorLogging.add(curRecord);
            } else {
                // 更新次数
                loggingMap.put(curRecord, loggingMap.get(curRecord) + 1);
            }
        }
        // 打印后8条记录
        if (errorLogging.size() > 8) {
            for (int i = errorLogging.size() - 8; i < errorLogging.size(); i++) {
                String currRecord = errorLogging.get(i);
                System.out.println(currRecord + " " + loggingMap.get(currRecord));
            }
        } else {
            for (int i = 0; i < errorLogging.size(); i++) {
                String currRecord = errorLogging.get(i);
                System.out.println(currRecord + " " + loggingMap.get(currRecord));
            }
        }
        scan.close();
    }
}
